#include <iostream>
#include <log4cpp/Category.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Priority.hh>
using namespace std;
using namespace log4cpp;

void test0(){
    // 1. 指定布局
    PatternLayout * ptn = new PatternLayout();
    ptn->setConversionPattern("%d %c: [%p] %m%n");

    // 2. 创建输出器与布局绑定
    OstreamAppender * pos = new OstreamAppender("console", &cout);
    pos->setLayout(ptn);

    // 3.创建记录器
    Category& sub = Category::getInstance("sub");

    // 4.设置优先级和目的地
    sub.setPriority(Priority::DEBUG);
    sub.setAppender(pos);

    // 5. 利用记录器写日志
    sub.error("This is an error msg");
    sub.warn("This is a warn msg");
    sub.info("This is an info msg");
    sub.debug("This is a debug msg");
    sub.notice("This is a notice msg");

    //回收log4cpp使用过程中的资源（以防万一）不要自己delete
    Category::shutdown();
}

int main(void){
    test0();
    return 0;
}

